#!/usr/bin/env bash

yum install -y openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel
wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
tar -xzvf Python-3.6.5.tgz
cd Python-3.6.5
./configure --prefix=/usr/local/python
make
make install
cd /usr/bin
mv python python.bak
mv pip pip.bak
ln -s /usr/local/python/bin/python3.6 /usr/bin/python
ln -s /usr/local/python/bin/pip3.6 /usr/bin/pip

sed -i 's@#!/usr/bin/python@#!/usr/bin/python2@g' /usr/bin/yum
sed -i 's@#!/usr/bin/python@#!/usr/bin/python2@g' /usr/bin/yum-builddep
sed -i 's@#!/usr/bin/python@#!/usr/bin/python2@g' /usr/bin/yum-config-manager
sed -i 's@#!/usr/bin/python@#!/usr/bin/python2@g' /usr/bin/yum-debug-dump
sed -i 's@#!/usr/bin/python@#!/usr/bin/python2@g' /usr/bin/yum-debug-restore
sed -i 's@#!/usr/bin/python@#!/usr/bin/python2@g' /usr/bin/yumdownloader
sed -i 's@#!/usr/bin/python@#!/usr/bin/python2@g' /usr/bin/yum-groups-manager